package net.wofly.sale.commission.validator;

import net.wofly.sale.commission.domain.CommissionCfg;
import org.springframework.util.StringUtils;

/**
 * Created by siqingwei on 2017/12/31.
 */
public class CommissionCfgValidator {

    /**
     * 换行符
     */
    private static String lineSeparator = System.getProperty("line.separator");

    public static String validateAddCommissionCfgParams(CommissionCfg commissionCfg) {
        StringBuffer stringBuffer = new StringBuffer();

        if (commissionCfg == null) {
            stringBuffer.append("佣金配置信息(commissionCfg)不能为空！").append(lineSeparator);
        } else {
            if (StringUtils.isEmpty(commissionCfg.getUserID()) && StringUtils.isEmpty(commissionCfg.getRoleID())) {
                stringBuffer.append("用户id(userID), 角色ID(roleID)不能都为空！").append(lineSeparator);
            }
            if (null == commissionCfg.getCommissionRate()) {
                stringBuffer.append("提成比例(commissionRate)不能为空！").append(lineSeparator);
            }
            if (null == commissionCfg.getDenominator() || commissionCfg.getDenominator() <= 0) {
                stringBuffer.append("提成比例分母(denominator)配置不能为空且不能小于等于0！").append(lineSeparator);
            }
        }

        return stringBuffer.toString();
    }

    public static String validateUpdateCommissionCfgParams(CommissionCfg commissionCfg) {
        StringBuffer stringBuffer = new StringBuffer();

        if (commissionCfg == null) {
            stringBuffer.append("佣金配置信息(commissionCfg)不能为空！").append(lineSeparator);
        } else {
            if (StringUtils.isEmpty(commissionCfg.getCommissionCfgID())) {
                stringBuffer.append("佣金配置id(commissionCfgID)不能为空！").append(lineSeparator);
            }
            if (StringUtils.isEmpty(commissionCfg.getUserID()) && StringUtils.isEmpty(commissionCfg.getRoleID())) {
                stringBuffer.append("用户id(userID), 角色ID(roleID)不能都为空！").append(lineSeparator);
            }
            if (null == commissionCfg.getCommissionRate()) {
                stringBuffer.append("提成比例(commissionRate)不能为空！").append(lineSeparator);
            }
            if (null == commissionCfg.getDenominator() || commissionCfg.getDenominator() <= 0) {
                stringBuffer.append("提成比例分母(denominator)配置不能为空且不能小于等于0！").append(lineSeparator);
            }
        }

        return stringBuffer.toString();
    }

    public static String validateGetSaleCommissionMonthSumParams(Integer sumDuration, Long sumTime) {
        StringBuffer stringBuffer = new StringBuffer();

        if (null == sumDuration) {
            stringBuffer.append("统计时长(sumDuration)不能为空！").append(lineSeparator);
        }

        if (null == sumTime) {
            stringBuffer.append("统计所在时间(sumTime)不能为空！").append(lineSeparator);
        }

        return stringBuffer.toString();
    }

    public static String validateGetSaleCommissionDetailParams() {
        StringBuffer stringBuffer = new StringBuffer();

        return stringBuffer.toString();
    }

    public static String validateGetCommissionRateByUserParams(String userID) {
        StringBuffer stringBuffer = new StringBuffer();

        if (StringUtils.isEmpty(userID)) {
            stringBuffer.append("用户id(userID)不能为空！").append(lineSeparator);
        }

        return stringBuffer.toString();
    }

    public static String validateDelCommissionCfgParams(String commissionCfgID) {
        StringBuffer stringBuffer = new StringBuffer();
        if (StringUtils.isEmpty(commissionCfgID)) {
            stringBuffer.append("佣金配置id(commissionCfgID)不能为空！").append(lineSeparator);
        }
        return stringBuffer.toString();
    }
}
